<template>
  <div class="hello">
<!--    <h1>{{ msg }}</h1>-->
    <el-table
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="手机号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="180">
      </el-table-column>
    </el-table>

    <el-pagination
      background
      align="right"
      layout="prev, pager, next"
      :total="total"
      :page-size="pageSize"
      :page-count="pageCount"
      :current-page="currentPage"
      @current-change="goPage">
    </el-pagination>
  </div>

</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: '整个Vue玩玩',
      tableData: [],
      pageSize: 10,
      total: 0,
      pageCount:2,
      currentPage:1,

    }
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    getTableData() {
      let params = {"currentPage":this.currentPage, "pageSize":this.pageSize}
      this.$http.post("/user/list",params).then(result => {
        this.tableData = result.data.data;
        this.total = result.data.totals;
      })
    },
    goPage(curr){
      this.currentPage = curr;
      this.getTableData();
    }
  },

  mounted(){
    this.getTableData();
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
